package com.cjh.lms.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.cjh.lms.mapper.TUserMapper;
import com.cjh.lms.pojo.TLockInfoExample;
import com.cjh.lms.pojo.TUser;
import com.cjh.lms.pojo.TUserExample;

@Service("LoginService")
public class LoginService {
	
	@Resource
	private TUserMapper tUserMapper;
	//登陆
	public TUser login(String username,String userpwd){
		TUserExample tUserExample = new TUserExample();
		TUserExample.Criteria criteria = tUserExample.createCriteria();
		criteria.andUsernameEqualTo(username);
		criteria.andUserpwdEqualTo(userpwd);
		List<TUser> user = tUserMapper.selectByExample(tUserExample);
		if (user.size()>0) {
			return user.get(0);
		}
		return null;
	}
	
	//修改密码
	public Object changPassword(String username,String password,String newPasswoed) {
		JSONObject jsonObject = new JSONObject();
		TUser tUser = new TUser();
		tUser.setUserpwd(newPasswoed);
		TUserExample tUserExample = new TUserExample();
		TUserExample.Criteria criteria = tUserExample.createCriteria();
		criteria.andUsernameEqualTo(username);
		criteria.andUserpwdEqualTo(password);
		if(tUserMapper.updateByExampleSelective(tUser, tUserExample)<1){
			jsonObject.put("errcode", 1);
			jsonObject.put("state",50001 );
			return jsonObject;
		}
		jsonObject.put("result", 00);
		return jsonObject;
	}
}
